import BasicController from './../../BasicController'
import InternalTradeModel from '../../../model/basic/logistics/InternalTradeModel'
import ErrorHandlerCode from './../../../util/ErrorHandlerCode'

class InternalTradeController extends BasicController{
    insert(req, res){
        InternalTradeModel.insert(req.body).then((data) => {
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }
    updateRecord(req, res){
        InternalTradeModel.update(req.body).then((data) => {
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }
    deleteById(req, res){
        InternalTradeModel.delete(req.body.id).then((data) => {
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }
    findById(req, res){
        InternalTradeModel.findById(req.body.id).then((data) => {
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }
    findByPage(req, res){
        req.body.page_size = req.body.page_size || 10;
        req.body.page_no = req.body.page_no || 1;
        InternalTradeModel.findByPage(req.body).then((data) => {
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }
    findAll(req, res){
        InternalTradeModel.findAll().then((data) => {
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }
}
module.exports = new InternalTradeController();